<%@ page language="java" import="java.util.*"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
String path = request.getContextPath();
String app_version = net.zoneland.greenleaf.GLOBAL.APP_VERSION;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=10;IE=9;IE=8;" />	
  		<!-- Title and other stuffs -->
  		<title>后台管理系统</title> 
  		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  		<script src="<%=path %>/js/greenleaf/jquery-1.8.3.js"></script> <!-- jQuery -->		
  		<script type="text/javascript">
	  		var path = "<%=path %>";
	  		var app_version = "<%=app_version %>";  
  		</script>
 </head>
 <body>
<div id="mainbar" class="mainbar">
 <!-- Page heading -->
	<div class="page-head">
	    <h2 class="pull-left"><i class="icon-home"></i> 系统配置列表</h2>
        <!-- Breadcrumb -->
        <div class="bread-crumb pull-right">
          <a href="javascript:void()"><i class="icon-home"></i> 系统配置管理</a> 
          <!-- Divider -->
          <span class="divider">/</span> 
          <a href="javascript:void()" class="bread-current">系统配置列表</a>
        </div>
        <div class="clearfix"></div>
	</div>
	<!-- Page heading ends -->

	<!-- Matter -->
	<div class="matter">
        <div class="container">
        <!-- 页面的内容开始. -->
        <!-- Table -->
            <div class="row">
              <div class="col-md-2">
                <div class="widget">
                <div class="widget-head">
                  <div class="pull-left">缓存列表</div>
                  <div class="widget-icons pull-right">
                    	<!-- 这里是标题栏靠右显示内容，如最大最小化按钮 -->
                  </div>  
                  <div class="clearfix"></div>
                </div>
                  <div class="widget-content">
	                    <table class="table table-striped table-bordered table-hover">
	                      <tbody>
	                      	<td height="600" id="ul_cacheNames" style="padding-left:20px">
	                      	
	                      	
	                      	</td>
	                      </tbody>
	                    </table>
	                    <div class="widget-foot">
	                        <ul class="pagination pull-right">
	                          
	                        </ul>                     
	                      <div class="clearfix"></div> 
	                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-10">
                <div class="widget">
                <div class="widget-head">
                  <div class="pull-left">缓存详细对象信息</div>
                  <div class="widget-icons pull-right">
                    	<!-- 这里是标题栏靠右显示内容，如最大最小化按钮 -->
                  </div>  
                  <div class="clearfix"></div>
                </div>
                  <div class="widget-content">
	                    <table class="table table-striped table-bordered table-hover">
	                      <thead id="sys_ehcache_detaillist_thead"></thead>
	                      <tbody id="sys_ehcache_detaillist_tbody">
	                      	
	                      </tbody>
	                    </table>
	                    <div class="widget-foot">
	                        <ul class="pagination pull-right">
                          		<div class="pagination" id="sys_ehcache_pagination"></div> <!-- End .pagination -->
                        	</ul>                   
	                      <div class="clearfix"></div> 
	                    </div>
                  </div>
                </div>
              </div>
            </div>
        <!-- 页面的内容结束. -->
        </div>
	</div>
	<!-- Matter ends -->
</div>
<!-- jQuery Flot -->
<script src="<%=path %>/js/greenleaf/actions/sys_ehcache_action.js"></script>
<script type="text/javascript">
	var sys_ehcache_list_currentpage = 1, sys_ehcache_list_pagesize = 10, sys_ehcache_list_maxpage = 1;
	
	$(document).ready(function(){
		getCacheNames();
	});
	function getCacheNames( fn ){
		var url = sys_ehcache_info_action.service.list;
		$.getJSON(url, null, function(json){
				var cache_list_html = "";
				$(json.data).each(function(){
					cache_list_html += "<li>";
	             	cache_list_html += "	<a onclick=\"getCacheDetail('first', '"+this+"')\" href=\"javascript:void(0)\">"+this+"</a>";		             	
	            	cache_list_html += "</li>"
				});
				$("#ul_cacheNames").html(cache_list_html);
				if(fn){fn();}
		 });
	}
	
	function getCacheDetail( page_flag, cacheName ){
		if("first"==page_flag){
			sys_ehcache_list_currentpage = 1;
		}else if("last"==page_flag){
			sys_ehcache_list_currentpage = sys_ehcache_list_maxpage;
		}else if("next"==page_flag){
			if(sys_ehcache_list_currentpage < sys_ehcache_list_maxpage){
				++sys_ehcache_list_currentpage;
			}
		}else if("preview"==page_flag){
			if(sys_ehcache_list_currentpage >1){
				--sys_ehcache_list_currentpage;
			}
		}
		var url = sys_ehcache_info_action.service.get;
		$.getJSON(url, {"cacheName":cacheName, "currentPage":sys_ehcache_list_currentpage, "pageSize":sys_ehcache_list_pagesize}, function(json){
				var cache_detail_html = "";
				var result = json.result;
				var hitratio = json.hitratio;
				var hitcount = json.hitcount;
				var cacheName = json.cacheName;
				var size = json.size;
				sys_ehcache_list_maxpage = json.pagination.totalPage;
				$(json.elements).each(function(){
					var key	= this.key;
					var value = JSON.stringify(this.value);
					var version = this.version;
					var hitCount = this.hitCount;
					if(value.length>500){
						value = value.substring(0,500)+"......";
					}						
					cache_detail_html += "<tr>";
					cache_detail_html += "<td style='border:1px solid #EEE; width:200px'>"+key+"</td>";
					cache_detail_html += "<td style='border:1px solid #EEE;' colspan=2>"+value+"</td>";
					cache_detail_html += "<td style='border:1px solid #EEE;width:50px; text-align:center;'>"+version+"</td>";
					cache_detail_html += "<td style='border:1px solid #EEE;width:50px; text-align:center;'>"+hitCount+"</td>";
					cache_detail_html += "</tr>";
				});
				$("#sys_ehcache_detaillist_tbody").html(cache_detail_html);
				var cache_info_html = "<th colspan=4><span style='margin-left:20px;'>缓存名称:" + cacheName;
				cache_info_html += "</span><span style='margin-left:20px;'>缓存对象数：" + size;
				cache_info_html += "</span><span style='margin-left:20px;'>命中次数：" + hitcount;
				cache_info_html += "</span></th><th width=50><input type=\"button\" value=\"清除\" onclick=\"deleteCache('0','"+cacheName+"','deleteAll')\"/></th> ";
				$("#sys_ehcache_detaillist_thead").html(cache_info_html);

				var sys_ehcache_pagination_html = "<li><a href=\"javascript:getCacheDetail('first','"+cacheName+"')\" title=\"First Page\">首页</a></li><li><a href=\"javascript:getCacheDetail('preview','"+cacheName+"')\" title=\"Previous Page\">上一页</a></li>";
				var count=0;
				for(var i=sys_ehcache_list_currentpage-3; i<=sys_ehcache_list_maxpage && i<sys_ehcache_list_currentpage+7 && count <7; i++){
					if(i > 0){
						if(i==sys_ehcache_list_currentpage-3){
							if(sys_ehcache_list_currentpage > 3){
								sys_ehcache_pagination_html += "...";
								count++;
								continue;
							}
						}
						sys_ehcache_pagination_html += "<li><a href=\"javascript:sys_ehcache_list_currentpage="+i+";getCacheDetail('"+sys_ehcache_list_currentpage+"','"+cacheName+"')\" class=\"number ";
						if(sys_ehcache_list_currentpage == i){
							sys_ehcache_pagination_html += "current";
						}						
						sys_ehcache_pagination_html += " title=\""+i+"\">"+i+"</a></li>";
						count++;
					}
				}
				if(sys_ehcache_list_maxpage>sys_ehcache_list_currentpage+3){
					sys_ehcache_pagination_html += "...";
					sys_ehcache_pagination_html += "<li><a href=\"javascript:sys_ehcache_list_currentpage="+sys_ehcache_list_maxpage+";getCacheDetail('"+sys_ehcache_list_currentpage+"','"+cacheName+"')\" class=\"number ";
					if(sys_ehcache_list_currentpage == sys_ehcache_list_maxpage){
						sys_ehcache_pagination_html += "current";
					}						
					sys_ehcache_pagination_html += " title=\""+sys_ehcache_list_maxpage+"\">"+sys_ehcache_list_maxpage+"</a><li>/";
				}					
				sys_ehcache_pagination_html += "<li><a href=\"javascript:getCacheDetail('next','"+cacheName+"')\" title=\"Next Page\">下一页</a></li><li><a href=\"javascript:getCacheDetail('last','"+cacheName+"')\" title=\"Last Page\">末页</a></li>";
				$("#sys_ehcache_pagination").html(sys_ehcache_pagination_html);
		 });	
	}
	
	function deleteCache(key , cacheName, handel){
		var url = sys_ehcache_info_action.service.remove;
		alert(url);
		$.getJSON(url, {"cacheName":cacheName, "handel":handel, "key":key}, function(json){
			alert(json.message);
			getCacheDetail( cacheName );
		});
	}
	
</script>
</body>